package org.lanqiao.api.product;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.lanqiao.common.Constants;
import org.lanqiao.common.JsonResult;
import org.lanqiao.common.JsonResultWriter;
import org.lanqiao.pojo.ProductPOJO;
import org.lanqiao.service.ProductServiceImpl;

/**
 * Servlet implementation class ChangeProductServlet
 */
@WebServlet("/api/product/changeproduct")
public class ChangeProductServlet extends HttpServlet {
	//更改商品信息，通过商品id 成功返回整数
	protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		ProductPOJO product=new ProductPOJO();
		product.setProductId(request.getParameter("productId"));//商品编号
		product.setProductName(request.getParameter("productName"));//商品名称
		product.setProductColor(request.getParameter("productColor"));//商品颜色
		product.setPrice(request.getParameter("price"));//商品价格
		product.setCategoryId(request.getParameter("categoryId"));//商品类别ID  PRODUCT_IS_SALE,PRODUCT_IS_LACK,PRODUCT_STATUS
		product.setSale(request.getParameter("isSale"));//是否出售
		product.setLack(request.getParameter("isLack"));//是否缺货
		product.setStatus(request.getParameter("status"));//产品状态
		
		
		JsonResult result=null;
		try {
			ProductServiceImpl productService=new ProductServiceImpl();
			int list=productService.changeProductService(product);
			if(list>0) {
				result=new JsonResult("修改成功",Constants.STATUS_SUCCESS,list);
			}else {
				result=new JsonResult("修改失败",Constants.STATUS_UNFOUND);
			}
		}catch(Exception e){
			result=new JsonResult("修改异常",Constants.STATUS_FAILURE);
		}
		
		JsonResultWriter.writer(response,result);
		
	}

}
